<%@page import="java.util.*"%>
<%@page import="com.ks.sgms.dao.*" %>
<%@page import="com.ks.sgms.entity.*" %>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>学生成绩管理页</title>
</head>
<%
	ScoreDao dao = new ScoreDao();
	List<Score> list = dao.getAllScore();
	request.setCharacterEncoding("UTF-8");
	//获取名为"student_id"的值
	String student_id = request.getParameter("student_id");
	String class_name = request.getParameter("class_name");
	//如果student_id是空的，则代表无需查询，直接查询全部student
	//如果不是空的，则代表需要查询，仅展示查询的数据
	if((student_id==null && class_name == null) || (student_id == "" && class_name == "") ){
		list = dao.getAllScore();
		
	}else{
		
		Student s = new Student();
		if(class_name == "" && student_id != ""){
			list = dao.selectScoreByStudentId(student_id);
		}else if(class_name != "" && student_id == ""){
			list = dao.selectScoreByClass(class_name);
		}else{
			list = dao.selectScoreByStudentId(student_id);
		}
	}
%>
<body>
	<div>
		<h1>学生成绩管理</h1>
		<div class="box">
			<form action="score.jsp" method="post">
				学号：<input  type="text"  name="student_id" value="">
				班级：<input  type="text"  name="class_name" value="">
				<input type="submit"  value="查询">
			</form>	
			<a href="score-insert.jsp" style="width:50px">
				<button>添加<tton>
			</a>
		</div>	
		<table>
			<tr>
				<td colspan="8">数据库中数据如下所示:</td>
			</tr>
			<tr>
				<td>学号</td>
				<td>姓名</td>
				<td>班级</td>
				<td>课程</td>
				<td>成绩</td>
				<td>学期</td>
				<td colspan="2">操作</td>
			</tr>
			
			<%if(list!=null)
				for(int i = 0;i < list.size();i++){ %>
				<tr>
					<td><%=list.get(i).student_id%></td>
					<td><%=list.get(i).student_name%></td>
					<td><%=list.get(i).class_name%></td>
					<td><%=list.get(i).course_name%></td>
					<td><%=list.get(i).score%></td>
					<td><%=list.get(i).term%></td>
					<td><a href="score-update.jsp?student_id=<%=list.get(i).student_id%>&course_id=<%=list.get(i).course_id%>">
						<button>修改</button>
					</a>
					</td>
					<td>
					<a href="deleteScore?student_id_del=<%=list.get(i).student_id%>&course_id_del=<%=list.get(i).course_id%>">
						<button>删除</button>
					</a>
					</td>
				</tr>
			<%} %>
		</table>	
	</div>
</body>
<style type="text/css">
	div {
		margin: 0 auto;
		width: 80%;
	}
	
	table {
		border: 2px solid;
	}
	
	td {
		border: 1px solid;
		text-align: center;
		width: 200px;
		height: 30px;
	}
	.box{
		display: flex;
		flex-direction: row;
	}
</style>
</html>